package com.javasm.transfer.goods;

import com.javasm.domin.entity.Admin;
import com.javasm.domin.entity.Dept;
import com.javasm.domin.entity.goods.*;
import com.javasm.domin.vo.AdminVo;
import com.javasm.domin.vo.goods.GoodsVO;
import com.javasm.mapper.DeptMapper;
import com.javasm.mapper.goods.BaseBrandMapper;
import com.javasm.mapper.goods.BaseTypeMapper;
import com.javasm.mapper.goods.ColorMapper;
import com.javasm.mapper.goods.ProductMapper;
import com.javasm.transfer.base.BaseTransfer;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author：Drd
 * @Version：1.0
 * @Date：2022/1/17-10:23
 * @Since:jdk1.8
 * @Description:
 */
@Component
@RequiredArgsConstructor
public class GoodsTransfer extends BaseTransfer<Goods, GoodsVO> {

    private final ColorMapper colorMapper;

    private final BaseBrandMapper baseBrandMapper;

    private final BaseTypeMapper baseTypeMapper;

    private final ProductMapper productMapper;

    public List<GoodsVO> setInfo(List<Goods> list) {
        List<GoodsVO> goodsVOS = super.toVO(list);
        for (int i = 0; i < goodsVOS.size(); i++) {
            Goods goods = list.get(i);
            //对颜色进行赋值
            Color color = colorMapper.selectById(goods.getProductColorId());
            GoodsVO goodsVO = goodsVOS.get(i);
            goodsVO.setProductColorId(color == null ? "" : color.getColorName());
//对品牌进行赋值
            BaseBrand baseBrand = baseBrandMapper.selectById(goods.getBrandId());
            goodsVO.setBrandId(baseBrand == null ? "" : baseBrand.getBrandName());
//对类别进行赋值
            BaseType baseType = baseTypeMapper.selectById(goods.getTypeId());
            goodsVO.setTypeId(baseType == null ? "" : baseType.getTypeName());
//对产品信息进行赋值
            Product product = productMapper.selectById(goods.getProductId());
            goodsVO.setProductId(product == null ? "" : product.getProductName());

            if (goods.getGoodsStatus()  == null) {
                goodsVO.setGoodsStatus("未知");
            } else if (goods.getGoodsStatus() == 0) {
                goodsVO.setGoodsStatus("失效");
            } else if (goods.getGoodsStatus() == 1) {
                goodsVO.setGoodsStatus("有效");
            } else {
                goodsVO.setGoodsStatus("未知");
            }
        }
        return goodsVOS;
    }

    public GoodsVO set(Goods goods) {
        GoodsVO goodsVO = super.toVO(goods);

            //对颜色进行赋值
            Color color = colorMapper.selectById(goods.getProductColorId());
            goodsVO.setProductColorId(color == null ? "" : color.getColorName());
//对品牌进行赋值
            BaseBrand baseBrand = baseBrandMapper.selectById(goods.getBrandId());
            goodsVO.setBrandId(baseBrand == null ? "" : baseBrand.getBrandName());
//对类别进行赋值
            BaseType baseType = baseTypeMapper.selectById(goods.getTypeId());
            goodsVO.setTypeId(baseType == null ? "" : baseType.getTypeName());
//对产品信息进行赋值
            Product product = productMapper.selectById(goods.getProductId());
            goodsVO.setProductId(product == null ? "" : product.getProductName());

            if (goods.getGoodsStatus()  == null) {
                goodsVO.setGoodsStatus("未知");
            } else if (goods.getGoodsStatus() == 0) {
                goodsVO.setGoodsStatus("失效");
            } else if (goods.getGoodsStatus() == 1) {
                goodsVO.setGoodsStatus("有效");
            } else {
                goodsVO.setGoodsStatus("未知");
            }
        return goodsVO;
    }
}
